CREATE DATABASE sysusersdb
GO

USE sysusersdb
GO

CREATE LOGIN sysusers_dep_vu_prepare_login1 WITH PASSWORD = '123'
GO

CREATE USER sysusers_dep_vu_prepare_user1 FOR LOGIN sysusers_dep_vu_prepare_login1
GO

CREATE LOGIN sysusers_dep_vu_prepare_login2 WITH PASSWORD = '123'
GO

CREATE USER sysusers_dep_vu_prepare_user2 FOR LOGIN sysusers_dep_vu_prepare_login2;
GO

CREATE VIEW sysusers_dep_vu_prepare_view
AS
SELECT name, hasdbaccess, islogin, isntname, issqluser, issqlrole
FROM sys.sysusers
WHERE name LIKE '%sysusers_dep_vu_prepare_%' OR name = 'dbo' or name = 'guest'
ORDER BY name offset 0 rows
GO

CREATE PROC sysusers_dep_vu_prepare_proc
AS
SELECT name, hasdbaccess, islogin, isntname, issqluser, issqlrole
FROM sys.sysusers
WHERE name LIKE '%sysusers_dep_vu_prepare_%' OR name = 'dbo' or name = 'guest'
ORDER BY name
GO

CREATE FUNCTION sysusers_dep_vu_prepare_func()
RETURNS TABLE
AS
RETURN
    SELECT name, hasdbaccess, islogin, isntname, issqluser, issqlrole
    FROM sys.sysusers
    WHERE name LIKE '%sysusers_dep_vu_prepare_%' OR name = 'dbo' or name = 'guest'
    ORDER BY name offset 0 rows
GO